<!DOCTYPE html>
<html>
	<head>
		<title>Collegio Morgagni</title>
		<style>
		td {text-align:center}
		td a {display:block}
		table {width: 100%;}
		.studentroom1 {background-color: hsl(30,100%,75%)}
		.studentroom2 {background-color: hsl(30,100%,65%)}
		.studentroom3 {background-color: hsl(30,100%,55%)}
		.studentroom4 {background-color: hsl(30,100%,45%)}
		.commonroom {background-color: hsl(210,100%,75%)}
		.studentroom1:hover {background-color: hsla(30,100%,75%, .5)}
		.studentroom2:hover {background-color: hsla(30,100%,65%, .5)}
		.studentroom3:hover {background-color: hsla(30,100%,55%, .5)}
		.studentroom4:hover {background-color: hsla(30,100%,45%, .5)}
		.commonroom:hover {background-color: hsla(210,100%,75%, .5)}
		</style>
		<script type="text/javascript">
			window.onload=function() {
				makeTable()
			}
			
			function createCommonRoom (name, ref, table, cellrow, cellcolumn, rowspan, colspan) {
				table[cellrow][cellcolumn].rowSpan = rowspan
				table[cellrow][cellcolumn].colSpan = colspan
				table[cellrow][cellcolumn].id = ref
				table[cellrow][cellcolumn].className = "commonroom"
				link = document.createElement('a')
				link.href = '/commonrooms/'+ref
				table[cellrow][cellcolumn].appendChild(link)
				link.appendChild(document.createTextNode(name))
				for(r=cellrow; r<cellrow+rowspan; r++) {
					for(c=cellcolumn; c<cellcolumn+colspan; c++) {
						if (r != cellrow || c!=cellcolumn) {table[r][c].parentNode.removeChild(table[r][c])}
					}
				}
			}
			function createStudentRoom (cell, floor, ord) {
				roomnumber = floor*100+ord
				link = document.createElement('a')
				link.href = '/studentrooms/'+roomnumber
				link.appendChild(document.createTextNode(roomnumber))
				cell.appendChild(link)
				cell.className = "studentroom"+floor
				cell.id = roomnumber
			}
			
			function makeTable() {
				var table = new Array()
				var row_num=15
				var cell_num=19
				var tab = document.getElementById('map')
				var tbo = document.createElement('tbody')
				for(r=0; r<row_num; r++){
					var tr = document.createElement('tr')
					table[r] = new Array()
					for(c=0;c<cell_num;c++) {
						table[r][c] = document.createElement('td')
						tr.appendChild(table[r][c])
					}
					tbo.appendChild(tr)
				}
				tab.appendChild(tbo)
				
				// quarto piano
				for(r=0, p=4;r<1;r++, p--) {
					for(c=0, s=1;c<6;c++, s++) {
						createStudentRoom(table[r][c], p, s)
					}
				}
				
				// ala ovest
				for(r=0, p=3;r<3;r++, p--) {
					for(c=8, s=1;c<16;c++, s++) {
						createStudentRoom(table[r][c], p, s)
					}
				}
				
				// ala nord
				for(r=3, s=9;r<9;r++, s++) {
					for(c=16, p=1;c<19;c++, p++) {
						createStudentRoom(table[r][c], p, s)
					}
				}
				
				// ala est, giardino
				for(r=9, p=1;r<12;r++, p++) {
					for(c=8, s=32;c<16;c++, s--) {
						createStudentRoom(table[r][c], p, s)
					}
				}
				
				// ala est, parcheggio
				for(r=12, p=3;r<15; r++, p--) {
					for(c=8, s=24;c<18;c++, s--) {
						createStudentRoom(table[r][c], p, s)
					}
				}
				
				// braccio
				for(r=13, p=2;r<15; r++, p--) {
					for(c=0, s=40;c<8;c++, s--) {
						createStudentRoom(table[r][c], p, s)
					}
				}
				
				// Consiliare
				createCommonRoom ('Consiliare', 'salaconsiliare', table, 1, 0, 3, 8)
				
				// Atrio consiliare
				createCommonRoom ('Atrio primo piano', 'atrioprimopiano', table, 4, 0, 2, 8)
				
				// Magna
				createCommonRoom ('Magna', 'aulamagna', table, 6, 2, 3, 6)

				// TV
				createCommonRoom ('TV', 'salatv', table, 6, 0, 3, 2)
				
				// Atrio piano terra
				createCommonRoom ('Atrio piano terra', 'ingresso', table, 9, 0, 1, 8)
				
				// Dante
				createCommonRoom ('Dante', 'saladante', table, 10, 0, 2, 2)
				
				// Stampanti
				createCommonRoom ('Stampanti', 'salastampanti', table, 12, 0, 1, 2)
				
				// Biblioteca
				createCommonRoom ('Biblioteca', 'biblioteca', table, 10, 2, 3, 4)
				
				// PC
				createCommonRoom ('PC', 'aulapc', table, 10, 6, 3, 2)
				
				// Galileo 1
				createCommonRoom ('Galileo 1', 'galileo1', table, 6, 8, 3, 2)
				
				// Galileo 2
				createCommonRoom ('Galileo 2', 'galileo2', table, 6, 10, 3, 2)
				
				// Galileo 3
				createCommonRoom ('Galileo 3', 'galileo3', table, 6, 12, 3, 2)
				
				// Galileo 4
				createCommonRoom ('Galileo 4', 'galileo4', table, 6, 14, 3, 2)
				
				// Palestra
				createCommonRoom ('Palestra', 'palestra', table, 3, 8, 3, 2)
				
				// Giardino
				createCommonRoom ('Giardino', 'giardino', table, 3, 10, 3, 6)
			}
		</script>
	</head>
	<body>
		<table id='map'></table>
	</body>
</html>
